<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        Promise.myRace = function (list =[]) {
            return new Promise((resolve, reject) => {
                list.forEach(item => {
                    Promise.resolve(item).then(res => {
                        resolve(res)
                    },err => {
                        reject(err)
                    })
                })
            })
        }
const p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve(1)
  }, 2000)
})

const p2 = new Promise((resolve, reject) => {
  setTimeout(() => {
    reject(2)
  }, 1000)
})

const p3 = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve(3)
  }, 5000)
})   
Promise.myRace([p1,p2,p3]).then(res => console.log(res)).catch(res =>console.log(res))
</script>
</body>
</html>